Method: Rugged::Blame#[]

Defined in:
ext/rugged/rugged_blame.c

#[](index) ⇒ Object

Returns the blame hunk data at the given index in blame.

Negative indices count backward from the end of the blame hunks (-1 is the last element).

Returns nil if no blame hunk exists at the given index.

[View source]

207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# File 'ext/rugged/rugged_blame.c', line 207

static VALUE rb_git_blame_get_by_index(VALUE self, VALUE rb_index)
{
	git_blame *blame;
	int index;
	uint32_t blame_count;

	Data_Get_Struct(self, git_blame, blame);
	Check_Type(rb_index, T_FIXNUM);

	index = NUM2INT(rb_index);
	blame_count = git_blame_get_hunk_count(blame);

	if (index < 0) {
		if ((uint32_t)(-index) > blame_count) {
			return Qnil;
		}

		return rb_git_blame_hunk_fromC(
			git_blame_get_hunk_byindex(blame, (uint32_t)(blame_count + index))
		);
	}

	if ((uint32_t)index > blame_count)
		return Qnil;

	return rb_git_blame_hunk_fromC(
		git_blame_get_hunk_byindex(blame, (uint32_t)index)
	);
}